<?php

$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$redis = require(__DIR__ . '/redis.php');
$rules = require(__DIR__ . '/rules.php');

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'language' => 'zh-CN',
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => '5z7pRxXHNUmPlfWgbVBkqNjEFhhYL5Ru',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'redis' => $redis,
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],

//        'mailer' => [
//            'class' => 'yii\swiftmailer\Mailer',
//            'useFileTransport' => false,
//            'transport' => [
//                'class' => 'Swift_SmtpTransport',
//                'host' => 'smtpdm.aliyun.com',//'smtpcloud.sohu.com',
//                'username' => 'aso@tf.staff.saasv.com',//'testin_ceshi',
//                'password' => 'aSMYh7291gblw',//'MAN0Mor2qZAND1GV',
//                'port' => '25',
//                //'encryption' => 'ssl',
//            ],
//        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                    'except' => [
                        'yii\web\HttpException:404',
                    ],
                    'logVars' => [],
                    'prefix' => function ($message) {
                        $uri = Yii::$app->request->url;
                        return "[$uri]";
                    },
                    'maxFileSize' => 4000000, //4GM
                    'fileMode' => 0777,
                ],
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['info'],
                    'categories' => ['admin'],
                    'except' => [
                        'yii\web\HttpException:404',
                    ],
                    'logVars' => [],
                    'prefix' => function ($message) {
                        $uri = Yii::$app->request->url;
                        return "[$uri]";
                    },
                    'logFile' => '@app/runtime/logs/admin.log',
                    'maxFileSize' => 4000000, //4GM
                    'fileMode' => 0777,
                ],
            ],
        ],

        'assetManager' => [
            'bundles' => [
                'yii\web\JqueryAsset' => [
                    'sourcePath' => null,   // 一定不要发布该资源
                    'js' => [
                        'http://qz-cdn.saasv.com/ttqz/js/jquery-2.0.3.min.js',
                    ]
                ],
                'yii\grid\GridViewAsset' => [
                    'sourcePath' => null,   // 一定不要发布该资源
                    'js' => [
                        'http://qz-cdn.saasv.com/ttqz/js/yii.gridView.js',
                    ]
                ],
                'yii\validators\ValidationAsset' => [
                    'sourcePath' => null,   // 一定不要发布该资源
                    'js' => [
                        'http://qz-cdn.saasv.com/ttqz/js/yii.validation.js',
                    ]
                ],
                'yii\widgets\ActiveFormAsset' => [
                    'sourcePath' => null,   // 一定不要发布该资源
                    'js' => [
                        'http://qz-cdn.saasv.com/ttqz/js/yii.activeForm.js',
                    ]
                ],
                'yii\web\YiiAsset'=> [
                    'sourcePath' => null,   // 一定不要发布该资源
                    'js' => [
                        'http://qz-cdn.saasv.com/ttqz/js/yii.js',
                    ],
                ],
                'yii\captcha\CaptchaAsset'=> [
                    'sourcePath' => null,   // 一定不要发布该资源
                    'js' => [
                        'http://qz-cdn.saasv.com/ttqz/js/yii.captcha.js',
                    ],
                ],
                
                'yii\bootstrap\BootstrapAsset' =>[
                    'sourcePath' => null,   // 一定不要发布该资源
                    'js' => [
                        'http://qz-cdn.saasv.com/ttqz/js/bootstrap.js',
                    ],
                    'css' => [
                        'http://qz-cdn.saasv.com/ttqz/css/bootstrap.min.css',
                    ]
                ],
                'yii\bootstrap\BootstrapPluginAsset' =>[
                    'sourcePath' => null,   // 一定不要发布该资源
                    'js' => [
                        'http://qz-cdn.saasv.com/ttqz/js/bootstrap.js',
                    ],
                ],
                'yii\bootstrap\BootstrapThemeAsset' =>[
                    'sourcePath' => null,   // 一定不要发布该资源
                    'css' => [
                        'http://qz-cdn.saasv.com/ttqz/css/bootstrap-theme.css',
                    ]
                ],
                
            ],
            
        ],
        'db' => $db,
        'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'showScriptName' => false,
            'enablePrettyUrl' => true,
            'rules' => $rules
        ],
        'formatter' => [
            'dateFormat' => 'Y-M-d',
            'datetimeFormat' => 'php:Y-m-d H:i:s',
            'decimalSeparator' => ',',
            'thousandSeparator' => ' ',
            'currencyCode' => '￥',
            'sizeFormatBase' => 1000,
        ],
        'tool' => [
            'class' => 'app\components\Tool',
        ],
    ],

    'modules' => [
        'admin' => [
            'class' => 'app\modules\admin\Module',
        ],
    ],
    
    'params' => $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        'allowedIPs' => ['127.0.0.1', '::1'],
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        'allowedIPs' => ['127.0.0.1', '::1'],
    ];
}

return $config;
